import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import store from "@/store"
Vue.use(VueRouter)

const routes = [
	{
		path: '/',
		name: 'login',
		component: Login,
	},
	{
		path: '/home',
		name: 'home',
		component: () => import('@/views/Home.vue'),
		children: [
			{
				path: '/home/homeView',
				name: 'homeView',
				component: () => import('@/views/HomeView.vue')
			},
			{
				path: '/home/usersList',
				name: 'usersList',
				component: () => import('@/views/UsersList.vue')
			},
			{
				path: '/home/homeView',
				name: 'homeView',
				meta: {
					isShow: true
				},
				component: () => import('@/views/HomeView.vue')
			},
			{
				path: '/home/homeSet',
				name: 'homeSet',
				meta: {
					isShow: true
				},
				component: () => import('@/views/HomeSet.vue')
			},
			{
				path: '/home/usersList',
				name: 'usersList',
				component: () => import('@/views/UsersList.vue')
			},
			{
				path: '/home/roleList',
				name: 'roleList',
				component: () => import('@/views/RoleList.vue')
			},
			{
				path: '/home/permission',
				name: 'permission',
				component: () => import('@/views/Permission/Permission.vue')
			},
			{
				path: '/home/goodsList',
				name: 'goodsList',
				component: () => import('@/views/GoodsList/GoodsList.vue'),
			},
			{
				path: '/home/goodsList/AddGoodCom',
				name: 'goodsList',
				component: () => import('@/views/GoodsList/component/AddGoodCom.vue')
			},
			{
				path: '/home/classifyArg',
				name: 'classifyArg',
				component: () => import('@/views/ClassifyArg.vue')
			},
			{
				path: '/home/goodsClassify',
				name: 'goodsClassify',
				component: () => import('@/views/GoodsClassify.vue')
			},
			{
				path: '/home/orderList',
				name: 'orderList',
				component: () => import('@/views/OrderList.vue')
			},
			{
				path: '/home/dataReport',
				name: 'dataReport',
				component: () => import('@/views/DataReport.vue')
			},
		]
	}

]

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})

router.beforeEach((to, from, next) => {
	if (to.matched.some(item => item.meta.isShow)) {
		if (store.state && store.state.isToken) {
			next() //放行
		} else {
			next("/") //登录页
		}
	} else {
		next()
	}
})

export default router
